<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="vue-2.2.1.js"></script>
    <script src="vue-router-2.3.1.js"></script>
</head>
<body>
    <div id="app">
        <router-link to="/login">登入</router-link>

        <router-link to="/register/itcast">注册</router-link>

        <router-view></router-view>
    </div>
</body>


<script>
    //准备组件
    var App = Vue.extend({});
    
    var login = Vue.extend({
        template:'<div><h1>登入</h1></div>'
    });

    var register = Vue.extend({
        template:'<div><h1>注册{{name}}</h1></div>',
        data:function(){
            return {
                name:''
            }
        },
        created:function(){
            this.name =  this.$route.params.name;
        }
    });

    var router = new VueRouter({
        routes:[
            {path:'/',redirect:'/login'},
            {path:'/login',component:login},
            {path:'/register/:name',component:register}
        ]
    });

    var vm  = new Vue({
        el:'#app',
        router:router,
        watch:{
            '$route':function (newroute,oldroute) {
                console.log(newroute,oldroute);
            }
        }
    });


</script>
</html>